import { ref, onMounted } from "vue";
export default () => {
    const keyword = ref("");
    /* list  [{name:"html",state:false}] */
    const list = ref([]);
    /* 判断一下localStorage是否有值 */
    onMounted(() => {
        /* getStorage */
        var items = JSON.parse(localStorage.getItem("items"));
        if (items) {
            list.value = items;
        }

    })
    const handleEnter = () => {
        var item = list.value.find((val) => keyword.value == val);
        if (item) {
            alert("值重复");
        } else {
            list.value.push({
                name: keyword.value,
                state: false,
            });
            keyword.value = "";
            // localStorage.setItem("items", JSON.stringify(list.value))
        }
    }
    return {
        keyword,
        list,
        handleEnter
    }
}